home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cc04.arc / YRSTSUP.C < prev   
Encoding:
C/C++ Source or Header  |  1986-03-15  |  6.2 KB  |  360 lines

  1. /*
  2.     YRSTSUP.C
  3.     ShareNet Local Archive Utility Support Procedures
  4.     V4.42    02/07/84    by Mark Hurst and Kyle Powell
  5.  
  6.     For use with NetWare V4.0-X and -S
  7.  
  8.     Copyright (C) 1983, 1984 Novell, Inc.
  9. */
  10.  
  11.  
  12. #define LOCALBIT    0x80
  13. #define PERMNET     0x01
  14. #define TEMPNET     0x02
  15. #define NETBITS     0x03
  16.  
  17. #define READBIT     0x01
  18. #define WRITEBIT    0x02
  19. #define OPENBIT     0x04
  20. #define CREATEBIT    0x08
  21. #define DELETEBIT    0x10
  22. #define OWNEDBIT    0x20
  23. #define SEARCHBIT    0x40
  24. #define MODIFYBIT    0x80
  25.  
  26. #include    "ctype.h"
  27. #include    "stdio.h"
  28.  
  29. #define     VARPATH     '^' - 'A'
  30.  
  31. #define     TRUE        1
  32. #define     FALSE        0
  33.  
  34. #define     MAXVOLUMES    16
  35. #define     MAXSPECS    100
  36. #define     LISTSIZE    250
  37.  
  38. #define     ALLMODE     1
  39. #define     MODMODE     2
  40. #define     SELMODE     3
  41.  
  42. extern    unsigned restorerights;
  43.  
  44. int    imin(a, b)
  45. int    a,b;
  46. {
  47.     if (a<b) return (a);
  48.     else return (b);
  49. }
  50.  
  51. unsigned umin(a, b)
  52. unsigned a,b;
  53. {
  54.     if (a<b) return (a);
  55.     else return (b);
  56. }
  57.  
  58. long    lmin(a, b)
  59. long    a,b;
  60. {
  61.     if (a<b) return (a);
  62.     else return (b);
  63. }
  64.  
  65. char    inline[80];
  66. /* buffered input of strings from console.  Forces first character to
  67.    be non-space.  returns first byte of input string.  If break character
  68.    detected, then the entire string is converted to 0x03, 0x00
  69. */
  70. char    getstr(t, mx)
  71. int    mx;
  72. char    *t;
  73. {
  74.     int    i, j;
  75.     char    ch;
  76.  
  77.     i = 0;
  78.     while ((ch=getch()) != 0x0D && ch != 0x03 && ch != 0x1B) {
  79.         switch(ch) {
  80.         case 0x08: /* backspace */
  81.             if (i) {
  82.                 i--;
  83.                 cprintf("\10 \10");
  84.             }
  85.             break;
  86.         default:
  87.             if (ch < 0x20) break;
  88.             if (!i && ch == 0x20) break;
  89.             if (i >= mx) {putch(7); break;}
  90.             putch(ch);
  91.             t[i++] = ch;
  92.         }
  93.     }
  94.     if (ch == 0x0D) {
  95.         t[i] = 0;
  96.         return (t[0]);
  97.     }
  98.     /* BREAK CHARACTER or ESCAPE DETECTED, CANCEL LINE and return char */
  99.  
  100.     t[0] = ch;
  101.     t[1] = 0;
  102.     return (ch);
  103. }
  104.  
  105. yes(q)
  106. char    *q;
  107. {
  108.     char    ch;
  109.  
  110.     ch = 'x';
  111.     while (ch != 'Y' && ch != 'N') {
  112.         cprintf("%s", q);
  113.         ch = getstr(inline, 3);
  114.         if (ch == 3) abort();
  115.         ch = toupper(ch);
  116.         if (!ch) {ch = 'N'; cprintf("No");}
  117.         cprintf("\r\n");
  118.     }
  119.     if (ch == 'Y') return (TRUE);
  120.     else return (FALSE);
  121. }
  122.  
  123. invertword(pword)
  124. char *pword;
  125. {
  126.     char    temp;
  127.  
  128.     temp = pword[0];
  129.     pword[0] = pword[1];
  130.     pword[1] = temp;
  131. }
  132.  
  133.  
  134. /*    SECTION TO SET THE DIRECTORY PATH MAPPINGS AND MODIFY THEM
  135.         AS THE SUBDIRECTORY STRUCTURE IS TRAVERSED
  136. */
  137.  
  138.  
  139. NewTemp (drive, handle, path,rhandle)
  140.     int    drive, handle,*rhandle;
  141.     char    *path;
  142. {
  143.     int    old, ccode, length;
  144.     char    flag, s[300], r[40];
  145.  
  146.     old = GetHandle (drive, &flag);
  147.     s[1] = 0;
  148.     s[2] = 19;
  149.     s[3] = handle;
  150.     s[4] = drive + 'A';
  151.     s[5] = strlen(path);
  152.     strcpy(&s[6], path);
  153.     length = 4 + s[5];
  154.     movmem(&length, s, 2);
  155.  
  156.     r[0] = 38;
  157.     r[1] = 0;
  158.     ccode = DirPath (s, r);
  159.     if (ccode == 0xFE) LockError();
  160.     else if (ccode) return (ccode);
  161.     *rhandle = r[2];
  162.     if (old != 0) {
  163.         /*release old handle*/
  164.         s[0] = 2;
  165.         s[1] = 0;
  166.         s[2] = 20;
  167.         s[3] = old;
  168.         DirPath (s, r);
  169.     }
  170.     return (0);
  171. }
  172.  
  173.  
  174.  
  175. /*    ROUTINE TO CREATE A NEW DIRECTORY PATH        */
  176. static struct NewDirStruct {
  177.     int    TotalLength;
  178.     char    Request;
  179.     char    Handle;
  180.     char    AccessMask;
  181.     char    SpecLength;
  182.     char    Spec[16];
  183. }    New = {0};
  184.  
  185.  
  186.  
  187. BackPath (ModPath, buff)
  188.     char    *ModPath, *buff;
  189. {
  190.     char    *end, *ans;
  191.     int    i, len;
  192.  
  193.  
  194.     SetB (0, buff, 16);
  195.     len = strlen (ModPath);
  196.     if (len == 0) return;
  197.     if ((FindB ('/', ModPath, len) == -1)
  198.     &&  (FindB ('\\', ModPath, len) == -1)
  199.     &&  (FindB (':', ModPath, len) == -1)) {
  200.         movmem (ModPath, buff, (len > 15) ? 15 : len);
  201.         *ModPath = 0;
  202.         return;
  203.     }
  204.  
  205.     end = &ModPath[len - 1];
  206.     while ((*end != '\\') && (*end != '/') && (*end != ':')) end--;
  207.     len = strlen (&end[1]);
  208.     movmem (&end[1], buff, (len > 15) ? 15 : len);
  209.     if (*end == ':') end++;
  210.     *end = 0;
  211. }
  212.  
  213.  
  214. MakeDir (drive,base, Path, handleptr)
  215.     char    *Path;
  216.     int    drive,base, *handleptr;
  217. {
  218.     int    ccode, handle, reply;
  219.     char    buff[16];
  220.  
  221.  
  222.  
  223.     ccode = NewTemp (drive, base, Path,&handle);
  224.     if (ccode == 0) {
  225.         *handleptr = handle;
  226.         return (0); /*success if path exists*/
  227.     }
  228.     BackPath (Path, buff);
  229.     if (buff[0] == 0) return (1); /*down to volume -- doesn't exist*/
  230.     ccode = MakeDir (drive,base, Path, &handle);
  231.     if (ccode != 0) return (ccode); /*problems below me*/
  232.     New.Request = 10;    /*make a new subdirectory*/
  233.     New.Handle = handle;
  234.     New.AccessMask = 0xFF;    /*always make with all rights*/
  235.     New.SpecLength = strlen (buff);
  236.     movmem (buff, New.Spec, New.SpecLength);
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.     New.TotalLength = New.SpecLength + 4;
  245.     reply = 0;
  246.     ccode = DirPath (&New, &reply);
  247.     if (ccode != 0) return (ccode); /*Dir Create failure*/
  248.     ccode = NewTemp (drive, handle, buff,&handle);
  249.     if (ccode) return (2);
  250.         /*can't go to path--shouldn't happen*/
  251.     *handleptr = handle;
  252.     return (0);
  253. }
  254.  
  255.  
  256. getpath (handle, buffer)
  257.     char    handle;
  258.     char    *buffer;
  259. {
  260.     char    s[10], r[300], ccode;
  261.     unsigned length;
  262.  
  263.     s[0] = 2;
  264.     s[1] = 0;
  265.     s[2] = 1;
  266.     s[3] = handle;
  267.     length = 295;
  268.     movmem(&length, r, 2);
  269.     ccode = DirPath(s, r);
  270.     if (ccode == 0xFE) LockError();
  271.     if (ccode) return (ccode);
  272.     r[r[2] + 3] = 0;
  273.     strcpy(buffer, &r[3]);
  274.     return (0);
  275. }
  276.  
  277.  
  278.  
  279. /*    --------- STRING PRIMITIVES ----------- */
  280.  
  281.  
  282. compress(s)
  283. char    *s;
  284. {
  285.     char    *c = s, ch;
  286.  
  287.     while (*s) if (!isspace(ch=*s++)) *c++ = ch;
  288.     *c = '\0';
  289. }
  290.  
  291.  
  292. SetB (byte, buff, len)
  293.     char        byte, *buff;
  294.     int        len;
  295. {
  296.     while (len-- > 0) *buff++ = byte;
  297. }
  298.  
  299. CmpB (b1, b2, len)
  300.     register char    *b1, *b2; int    len;
  301. {
  302.     register int    i;
  303.  
  304.     for (i=0; i<len; i++)
  305.         if (*b1++ != *b2++) return (i);
  306.     return (-1);
  307. }
  308.  
  309. FindB (b, s, len)
  310.     char    b, *s;
  311.     int    len;
  312. {
  313.     int    i;
  314.  
  315.     for (i=0; i<len; i++) {
  316.         if (b == s[i]) return (i);
  317.     }
  318.     return (-1);
  319. }
  320.  
  321.  
  322.  
  323. conupper(t)
  324. char    *t;
  325. {
  326.     while (*t) {*t = toupper(*t); t++;}
  327. }
  328.  
  329.  
  330. LockError()
  331. {
  332.     error("The Supervisor has the Directory System locked.");
  333.     myexit(0);
  334. }
  335.  
  336.  
  337.  
  338.  
  339. checkrights(drive, pmask)
  340. char    drive, pmask;
  341. {
  342.     char    ccode, mask, type;
  343.     char    s[20], r[10];
  344.  
  345.     s[0] = 3;
  346.     s[1] = 0;
  347.     s[2] = 3;
  348.     s[3] = GetHandle(drive, &type);
  349.     s[4] = 0; /* NULL PATH MOD SPEC, ASSUME CURRENT PATH (.) */
  350.     r[0] = 8;
  351.     r[1] = 0;
  352.     ccode = DirPath (s, r);
  353.     if (ccode == 0xFE) LockError();
  354.     else if (ccode) return(FALSE);
  355.     mask = r[2];
  356.     if (mask == 0xFF)  return (TRUE); /* OK TO BACK IT UP */
  357.     if ((mask & pmask) == pmask) return (TRUE);
  358.     else return (FALSE);
  359. }
  360.